package com.gxuwz.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 分割时间段
 * @author Administrator
 *
 */
public class TimeSplitUtils {
	
	//待去掉字符
	private static final String temp = "+";
	private static final String tempp = "至";
	
	//前后时间
	private static String openTime;
	private static String endTime;
	
	private static Date OT;
	private static Date ET;
	
	/**
	 * new实例可能会产生垃圾数据
	 */
	private static List<Date> dateList = new ArrayList<Date>();
	private static List<String> StringList = new ArrayList<String>();
	
	public static List<Date> timeSplit(String timeStr){
		//替换字符
		timeStr = timeStr.replace("+", "").replace("至", "");
		//截取字符串
		openTime = timeStr.substring(0, 19);
		endTime = timeStr.substring(21, timeStr.length());
//		System.out.println(timeStr);
//		System.out.println(openTime);
//		System.out.println(endTime);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			OT = sdf.parse(openTime);
			ET = sdf.parse(endTime);
			dateList.add(OT);
			dateList.add(ET);
			return dateList;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static List<String> timeSplitToString(String timeStr){
		//替换字符
		timeStr = timeStr.replace("+", "").replace("至", "");
		//截取字符串
		openTime = timeStr.substring(0, 19);
		endTime = timeStr.substring(21, timeStr.length());
		//清空缓存
		StringList.clear();
		StringList.add(openTime);
		StringList.add(endTime);
//		System.out.println(StringList);
		return StringList;
	}
}
